<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="jquery-1.8.2.min.js"></script>
    <style>
        .text {
            border: 1px solid green;
        }
    </style>
</head>
<body>
    <div><p>hello in a paragraph</p></div>
    <div>hello again!(with no p)</div>
</body>
<script>
    $(function () {
        $("div:has(p)").addClass("text");
    })
</script>
</html>